
const app = getApp();
import { cardVoucherList } from "../../../api/my"
import { getStorage } from "../../../utils/localStorage"
import { baseUrl } from "../../../api/release"
Page({
    data: {
        navData: {
            level: 2,
            title: "红包卡券"
        },
        listQuery: {
            pageNum: 1,
            pageSize: 10,
            useFlag: 1,
            userId: 0,
        },
        total: 0,
        list: [],
        imgUrl: baseUrl,
        navMargin: app.globalData.navHeight + app.globalData.navTop,
        showPull: true, //上拉加载更多状态
        user: getStorage('user'), //用户信息
    },
    onLoad(options) {
        this.setData({
            "listQuery.userId": getStorage('user').id,
             imgUrl: baseUrl,
        });
        console.log(this.data.user,'user');
        this.getCardList();
    },
    onReady() {

    },
    onShow() {

    },
    //获取列表数据
    getCardList() {
        let that = this.data;
        cardVoucherList(this.data.listQuery).then(res => {
            this.setData({
                list: [...that.list, ...res.data.rows],
                total: Math.ceil(res.data.total / that.listQuery.pageSize)
            });
        });
    },
    //顶部切换栏点击事件
    navTap(e) {
        let index = e.currentTarget.dataset.index;
        this.setData({
            list: [],
            "listQuery.useFlag": index
        });
        this.getCardList();
    },
    //核销记录按钮点击事件
    writeRecord() {
        wx.navigateTo({
            url: '/pagesWoDe/pages/wirteCodeJl/index',
        })
    },
    //列表点击事件
    listTap(e) {
        if (this.data.listQuery.useFlag === 1) {
            let item = e.currentTarget.dataset.item;
            wx.navigateTo({
                url: '/pagesWoDe/pages/wirteCode/index?id=' + item.id,
            })
        };
    },
    /* 上拉加载更多 */
    pullUp(e) {
        let that = this.data;
        if ((that.listQuery.pageNum + 1) <= that.total) {
            this.setData({
                showPull: false,
                "listQuery.pageNum": that.listQuery.pageNum += 1
            });
            this.getCardList();
        } else {
            this.setData({
                showPull: true
            });
        };
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})